﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsApplication1.DTO;

namespace WindowsFormsApplication1.DAO
{
    class ChamCongDAO
    {
        public static List<ChamCongDTO> ChamCong(int idNamHoc, int idHocKy)
        {
            List<ChamCongDTO> list = CreateList();
            list = ChamCongCoiThi(list, idNamHoc, idHocKy);
            return list;
        }

        internal static void ChamCong(ref ChamCongDTO info, int idNamHoc, int idHocKy)
        {
            GiaoVien_CongViecDAO.ChamCong(ref info, idNamHoc, idHocKy, Def.CV_CHAM_TIEULUAN_DOAN);
            GiaoVien_CongViecDAO.ChamCong(ref info, idNamHoc, idHocKy, Def.CV_CHAM_TRACNGHIEM_VANDAP);
            GiaoVien_CongViecDAO.ChamCong(ref info, idNamHoc, idHocKy, Def.CV_CHAM_TULUAN_THIMAY);
            GiaoVien_CongViecDAO.ChamCong(ref info, idNamHoc, idHocKy, Def.CV_NHAPDIEMTHI);
            GiaoVien_CongViecDAO.ChamCong(ref info, idNamHoc, idHocKy, Def.CV_RADE);
            GiaoVien_CongViecDAO.ChamCong(ref info, idNamHoc, idHocKy, Def.CV_TOCHUCPHONGTHI);
        }

        private static List<ChamCongDTO> ChamCongCoiThi(List<ChamCongDTO> list, int idNamHoc, int idHocKy)
        {
            for (int i = 0; i < list.Count; i++)
            {
                ChamCongDTO cc = list[i];
                ChamCongDAO.ChamCong(ref cc, idNamHoc, idHocKy);
                list[i] = cc;
                list[i].congCoiThi = BienBanCoiThiDAO.TinhCongCoiThi(list[i].maGiaoVien, idNamHoc, idHocKy);
                list[i].tongTiet = list[i].congChamBai + list[i].congCoiThi + list[i].congInDe + list[i].congRaDe + list[i].congToChuc;
            }
            return list;
        }


        private static List<ChamCongDTO> CreateList()
        {
            List<GiaoVienDTO> gvlist = GiaoVienDAO.GetList();
            List<ChamCongDTO> chamCongList = new List<ChamCongDTO>();

            foreach (GiaoVienDTO gv in gvlist)
            {
                ChamCongDTO cc = new ChamCongDTO(gv.maGiaoVien,gv.tenGiaoVien);
                cc.donVi = DonViDAO.GetTenDonVi(gv.maDonVi);
                chamCongList.Add(cc);
            }
            return chamCongList;
        }
    }
}
